package com.ycfmedical.bed.widgets;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;

import com.ycfmedical.bed.R;
import com.ycfmedical.bed.listener.IcontrolFreedom;

import cn.droidlover.xdroidmvp.log.XLog;

/**
 * Created by Administrator on 2017-04-14.
 */
@SuppressLint("ValidFragment")
public class ControlSelectDialog extends DialogFragment implements View.OnClickListener{
    private Context context;
    private View view;
    private IcontrolFreedom icontrolFreedom;
    private Button btn_sleep,btn_recess,btn_eat,btn_work,btn_save,btn_resetting;
    private boolean flag  = false;
    private int num = 0;
    public ControlSelectDialog(IcontrolFreedom icontrolFreedom){
        this.icontrolFreedom = icontrolFreedom;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        view = inflater.inflate(R.layout.dialog_test, container);
        initView();
        click();
        return view;
    }

    private void click() {
        btn_sleep.setOnClickListener(this);
        btn_recess.setOnClickListener(this);
        btn_eat.setOnClickListener(this);
        btn_work.setOnClickListener(this);
        btn_save.setOnClickListener(this);
        btn_resetting.setOnClickListener(this);

    }

    private void initView(){
        setCancelable(true);
        context = getContext();
        btn_sleep = (Button) view.findViewById(R.id.btn_sleep);
        btn_recess = (Button) view.findViewById(R.id.btn_recess);
        btn_eat = (Button) view.findViewById(R.id.btn_eat);
        btn_work = (Button) view.findViewById(R.id.btn_work);
        btn_save = (Button) view.findViewById(R.id.btn_save);
        btn_resetting = (Button) view.findViewById(R.id.btn_resetting);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_sleep:
                btn_sleep.setBackgroundResource(R.drawable.im_cheek_true);
                btn_recess.setBackgroundResource(R.drawable.im_cheek_false);
                btn_eat.setBackgroundResource(R.drawable.im_cheek_false);
                btn_work.setBackgroundResource(R.drawable.im_cheek_false);
                num = 1;
                flag = true;
                break;
            case R.id.btn_recess:
                btn_sleep.setBackgroundResource(R.drawable.im_cheek_false);
                btn_recess.setBackgroundResource(R.drawable.im_cheek_true);
                btn_eat.setBackgroundResource(R.drawable.im_cheek_false);
                btn_work.setBackgroundResource(R.drawable.im_cheek_false);
                num = 2;
                flag = true;

                break;
            case R.id.btn_eat:
                btn_sleep.setBackgroundResource(R.drawable.im_cheek_false);
                btn_recess.setBackgroundResource(R.drawable.im_cheek_false);
                btn_eat.setBackgroundResource(R.drawable.im_cheek_true);
                btn_work.setBackgroundResource(R.drawable.im_cheek_false);
                num = 3;
                flag = true;

                break;
            case R.id.btn_work:
                btn_sleep.setBackgroundResource(R.drawable.im_cheek_false);
                btn_recess.setBackgroundResource(R.drawable.im_cheek_false);
                btn_eat.setBackgroundResource(R.drawable.im_cheek_false);
                btn_work.setBackgroundResource(R.drawable.im_cheek_true);
                num = 4;

                flag = true;
                break;
            case R.id.btn_save:
                if(flag){
                    icontrolFreedom.setquicklyPostId(num);
                    dismiss();
                }else{
                    Toast.makeText(context,"请选择保存类型",Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_resetting:
                dismiss();
                break;
            default: break;
        }
    }
}
